<?php
/**
 * @Author: lopo
 * @Date:   2018-10-30 16:30:16
 * @Last Modified by:   Lopo
 * @Last Modified time: 2018-10-30 17:04:34
 */
namespace app\admin\controller;
use think\Controller;
use app\common\model\Notice as Noticemodel;

class Notice extends IndexBase
{

    public function noticelist()
    {
        $notice = new Noticemodel;
        $noticelist = $notice->getNoticePage();
        $this->assign('noticelist', $noticelist);
          return $this->fetch();
    }

     public function addnotice()
    {
        
          return $this->fetch();
    }

    public function ajax_add_notice(){
        $file = request()->file('pice');
        $info = $file->move( '../public/static/uploads');
        if($info){
            $getSaveName = str_replace("\\","/",$info->getSaveName());
            $_opt['sport_url'] = '/static/uploads/'.$getSaveName;
            $_opt['sportsman'] =  input('post.sportsman');
            $_opt['profile'] =  input('post.profile');
            $_opt['content'] =  input('post.content');
        }else{
            $this->error($file->getError());
        }
        $notice = new Noticemodel;
        $addnotice = $notice->addNoticeInfo($_opt);
       if($addnotice){
        $this->success('添加成功！');
       }else{
        $this->error('添加失败！');
       }

    }


    public function editnotice(){
        $notice = new Noticemodel;
        $_opt['id'] = input('id');
        $noticeInfo = $notice->getNoticeInfo($_opt);
        $this->assign('noticeInfo', $noticeInfo);
        return $this->fetch();
    }

    public function ajax_edit_notice(){
        
        if(!empty($_FILES['pice']['name'])){
            $file = request()->file('pice');
            $info = $file->move( '../public/static/uploads');
            if($info){
                $getSaveName = str_replace("\\","/",$info->getSaveName());
                $_opt['sport_url'] = '/static/uploads/'.$getSaveName;
               
            }
        }
        
       
        $_opt['sportsman'] =  input('post.sportsman');
        $_opt['profile'] =  input('post.profile');
        $_opt['content'] =  input('post.content');
        $_opt['id'] =  input('post.id');
        
        $notice = new Noticemodel;
        $addnotice = $notice->updateInfo($_opt);
       if($addnotice){
        $this->success('修改成功！');
       }else{
        $this->error('修改失败！');
       }

    }






}